<?php
include_once ('../global.php');
$page=isset($_GET['page'])?$_GET['page']:1;
$type=isset($_GET['type'])?$_GET['type']:1;
$page_size=isset($_GET['page_size'])?$_GET['page_size']:20;
$start=($page-1)*$page_size;
$where=" where is_del=0 and act_id='{$type}'";
$sql = "SELECT * FROM `bmw_active_sign_new`  {$where} order by id desc limit {$start},{$page_size}";
$list= $db->SelectSQL($sql);
foreach ($list as &$val){
    $sql_1="SELECT * FROM `player` WHERE pl_id=".$val['user_id'];
    $info=$db->SelectSQL($sql_1);
    $val['name']=$info?$info[0]['pl_cn_name']:"";
    $val['phone']=$info?$info[0]['pl_tele']:"";
    $val['act_text']="";
    $act_text="";
    if($val['act_id']==1){
        $val['act_text']=get_active($val['session']);
    }
    if($val['act_id']==3){
        $val['act_text']=get_jiazhang_active($val['session']);
    }
}
$sql_count = "SELECT count(*) as count FROM `bmw_active_sign_new` {$where}";
$info= $db->SelectSQL($sql_count);
$total_count=$info?$info[0]['count']:0;
$total_page=ceil($total_count/$page_size);


?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/assets/store/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content=""/>
    <link rel="stylesheet" href="css/mydata/amazeui.min.css"/>
    <link rel="stylesheet" href="css/mydata/app.css"/>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_783249_t6knt0guzo.css">
    <script src="css/mydata/jquery.min.js"></script>
    <script src="//at.alicdn.com/t/font_783249_e5yrsf08rap.js"></script>
    <style>

        .ordertime,.ordercount  {
            cursor: pointer;
        }


        .arror0 {
        }

        .arror1 {
            background-image: url("/assets/store/img/arrow-down.png");
            background-repeat: no-repeat;
            background-size: 5px 10px;
            background-position: right 5px center;
            padding-right: 10px !important;
        }

        .arror2 {
            background-image: url("/assets/store/img/arrow-up.png");
            background-repeat: no-repeat;
            background-size: 5px 10px;
            background-position: right 5px center;
            padding-right: 10px !important;
        }
        .getall_option {
            display: inline-block;
            margin-left: 20px;
        }

        .getall_option li {
            border-radius: 10px;
            display: inline-block;
            padding: 5px 10px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            cursor: pointer;
        }

        /*.getall_option li:first-child {*/
        /*    border-radius: 5px 0 0 5px*/
        /*}*/

        /*.getall_option li:last-child {*/
        /*    border-radius: 0 5px 5px 0;*/
        /*    margin-left: -4px;*/
        /*}*/

        .getall_option li.active {
            background-color: #0b76ac;
            color: white;
        }

    </style>
</head>

<body data-type="">
<div class="am-g tpl-g">



    <!-- 内容区域 start -->
    <div class="tpl-content-wrapper <?= empty($second) ? 'no-sidebar-second' : '' ?>">

        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <ul class="getall_option">
                                <li <?php if ($type == 1):echo 'class="active"'; endif; ?>>冠军训练营</li>
                                <li <?php if ($type == 3):echo 'class="active"'; endif; ?>>家长分享会</li>
                                <li <?php if ($type == 2):echo 'class="active"'; endif; ?>>试乘试驾</li>
                            </ul>
                        </div>

                        <div class="widget-body am-fr">
                            <div class="">
                                <a class="am-btn am-btn-default am-btn-success am-radius" style="float: none"
                                   href="javascript:;" id="excelout">导出
                                </a>
                            </div>
                        </div>
                        <div class="am-btn-group am-btn-group-xs  am-fr">

                            <div class="am-vertical-align-middle">
                                <button type="submit" style="font-size: 1rem" onclick="jump()"
                                        class="j-submit am-btn am-btn-secondary">搜索
                                </button>
                            </div>
                        </div>
                        <form id="my-form" class="am-form tpl-form-line-form" method="post">

                            <div class="am-scrollable-horizontal am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                                    <thead>
                                    <tr>
                                        <th >姓名</th>
                                        <th >手机号</th>
                                        <th >活动</th>
                                        <th >提交时间</th>
                                        <th >操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $uuids_str="";
                                    ?>
                                    <?php if($list){ ?>
                                        <?php foreach ($list as $item){ ?>
                                            <tr class="itemline">
                                                <td class="am-text-middle"><?php
                                                    echo $item['name'];

                                                    ?>
                                                </td>
                                                <td class="am-text-middle"><?php
                                                    echo $item['phone'];

                                                    ?>
                                                </td>
                                                <td class="am-text-middle"><?php
                                                    echo $item['act_text'];

                                                    ?></td>
                                                <td class="am-text-middle"><?php
                                                    echo $item['act_datetime'];

                                                    ?></td>
                                                <td class="am-text-middle">
                                                    <div class="tpl-table-black-operation">
                                                        <a href="javascript:;" class="item-delete tpl-table-black-operation-del"
                                                           data-id="<?= $item['ID'] ?>">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </a>



                                                    </div>
                                                </td>


                                            </tr>
                                        <?php } ?>
                                    <?php }else{ ?>
                                        <tr>
                                            <td colspan="12" class="am-text-center">暂无记录</td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>

                            <div class="am-u-lg-12 am-cf">

                                <div class="am-fr">
                                    <ul class="pagination">

                                        <?php if($page==1) {?>
                                            <li class="disabled"><span>«</span></li>
                                        <?php } ?>
                                        <?php for ($i = 1; $i <= $total_page; $i++) { ?>

                                            <?php if($page==$i) {?>
                                                <li class="active"><span><?php echo $i;?></span></li>
                                            <?php }else {?>
                                                <li><a href="/bmwjunior/mobile/activelist.php?page=<?php echo $i;?>&type=<?php echo $type;?>"><?php echo $i;?></a></li>

                                            <?php } ?>

                                        <?php } ?>
                                        <?php if($page<$total_page) {?>
                                            <li><a href="/bmwjunior/mobile/activelist.php?page=<?php echo $page+1;?>&type=<?php echo $type;?>">»</a></li>
                                        <?php } ?>
                                    </ul>

                                </div>
                                <div class="am-fr pagination-total am-margin-right">
                                    <div class="am-vertical-align-middle">总记录：<?= $total_count ?></div>
                                </div>
                            </div>
                        </form>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 内容区域 end -->

</div>
<script src="css/mydata/layer/layer.js"></script>
<script>
    $("#excelout").click(function (){
        var type=0;
        if ($('.getall_option li.active').index() == 1) {
            type=3;
        }else  if ($('.getall_option li.active').index() == 2) {
            type=2;
        }else {
            type=1;
        }
        window.location.href="/bmwjunior/mobile/exceldeal.php?type="+type
    })

    $('.getall_option li').click(function () {
        $('.getall_option li').removeClass('active');
        $(this).addClass('active');
        jump();
    });

    function jump() {
        var urls='';
        if ($('.getall_option li.active').index() == 1) {
            urls += '/bmwjunior/mobile/activelist.php?type=3';
        }else  if ($('.getall_option li.active').index() == 2) {
            urls += '/bmwjunior/mobile/testdrivelist.php?type=2';
        }else {
            urls += '/bmwjunior/mobile/activelist.php?type=1';
        }
        window.location.href = urls
    }

    // 删除元素
    var url = "/bmwjunior/mobile/deletdata.php?type=2";

    $('.item-delete').click(function () {
        var param = {};
        var id = $(this).attr('data-id');
        layer.confirm('确定要删除吗？', function (index) {
            $.post(url, {id:id}, function (result) {
                if(result.code==1){
                    layer.alert('删除成功',{ icon: 6, title: '提示' },function (){
                        window.location.reload();
                    });
                }else{
                    layer.alert('删除失败',{ icon: 5, title: '提示' });
                }
            },'json');
            layer.close(index);
        });
    });

</script>
</body>

</html>